package com.baidu.day02;

import java.util.ArrayList;
import java.util.List;

/**
 * Create with Intellij IDEA
 *
 * @Author Q
 * @date 2021/11/23/9:58
 */
public class ListRemoveDemo {
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();

        //创建学生对象
        Student s1 = new Student(1,"霍针");
        Student s2 = new Student(2,"吴签");
        Student s3 = new Student(3,"李泽鑫");

        Student s4 = new Student(1,"james");

        System.out.println(s1.equals(s4));

        list.add(s1);
        list.add(s2);
        list.add(s3);

        list.remove(s4);


        list.forEach(e-> System.out.println(e));

//        System.out.println(list);

//        for (int i = 0; i < list.size(); i++) {
//            System.out.println(list.get(i));
//        }

        //只读的for
//        for (Student s : list) {
//            System.out.println(s);
//        }

//        list.forEach(System.out::println);

        //list.forEach(e-> System.out.println(e));
    }
}

@SuppressWarnings("all")
class Student{
    private Integer id;

    private String name;

    //空参构造 - new
    public Student(){

    }

    //全参构造
    public Student(Integer id,String name){
        this.id = id;
        this.name = name;
    }

    //getter/setter

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    //alter+insert


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Student student = (Student) o;

        return id != null ? id.equals(student.id) : student.id == null;
    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Student{");
        sb.append("id=").append(id);
        sb.append(", name='").append(name).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
